home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000078_icon-group-sender_Wed Oct 18 16:27:45 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9INRMd22154
  4.     for icon-group-addresses; Wed, 18 Oct 2000 16:27:22 -0700 (MST)
  5. Message-Id: <200010182327.e9INRMd22154@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 18 Oct 2000 16:42:23 -0500
  7. From: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
  8. To: <icon-group@optima.CS.Arizona.EDU>
  9. Subject: Pipes in Icon
  10. Content-Disposition: inline
  11. X-Guinevere: 1.0.13 ; Oceaneering Int'l
  12. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id e9ILgWv18771
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15. Content-Length: 1520
  16.  
  17. I am having a little problem with Icon on Linux.
  18.  
  19. I would like to invoke a program /usr/bin/xyz from within an Icon program and use pipes to communicate with it.  I would send the command strings to xyz with a write(), and then read the results with a read().  It is important to understand that both the read() and the write() are called from within a single program.
  20.  
  21. I tried some code that looked something like this (assume xyz is already running):
  22.  
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. ...
  25. # to_xyz is the write pipe to /usr/bin/xyz
  26. # fr_xyz is the read pipe from /usr/bin/xyz
  27.  
  28. # Read lines from standard input, send them to xyz.
  29. # Then read xyz's response and print it to standard output.
  30.  
  31. while line_in := read() do {
  32.    write(to_xyz, line_in)
  33.    # Make sure buffer is flushed, then:
  34.    while line_out := read(fr_xyz) do
  35.       write(line_out)
  36. }
  37. ...
  38.  
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. The problem is, Icon's pipe facility won't permit setting up the pipes.  The 
  41. syntax is
  42.  
  43. fr_xyz := open("/usr/bin/xyz", "pr")     # read pipe
  44. to_xyz := open("/usr/bin/xyz", "pw")     # write pipe
  45.  
  46. This implies that each open() can open only a single, unidirectional pipe to a fresh instance of /usr/bin/xyz.  And that is true.  When I did this, I got two separate instances of xyz, each running a separate pipe.
  47.  
  48. So the question is, is there any way to accomplish this entirely within Icon?  I'm sure I could with C, or with a bash script.
  49.  
  50. Thanks.
  51. Charles Hethcoat
  52. Oceaneering Space Systems, Inc.
  53.  
  54.